﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;

namespace LFMTest
{
    partial class MainPage
    {
        lfm.Artist a = new lfm.Artist();
        ObservableCollection<lfm.Image> images = new ObservableCollection<lfm.Image>();

        public MainPage()
        {
            InitializeComponent();
            ResultPanel.DataContext = a;
            //gv_Photos.ItemsSource = images;
        }

        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            pRing.IsActive = true;
            ResultPanel.DataContext = await lfm.EndPoints.Artist.getInfo(tb_Input.Text, null, null);
            pRing.IsActive = false;
        }

        private async void b_Images_Click(object sender, RoutedEventArgs e)
        {
            pRing.IsActive = true;
            gv_Photos.ItemsSource = await lfm.EndPoints.Artist.getImages(tb_Input.Text, null, null, null, lfm.Order.popularity);
            //var similar = await lfm.EndPoints.Artist.getSimilar(tb_Input.Text, 30, null);
            //var search = await lfm.EndPoints.Artist.search(tb_Input.Text, 1, 50);
            //var tags = await lfm.EndPoints.Artist.getTopTags(tb_Input.Text, null);
            //var toptracks = await lfm.EndPoints.Artist.getTopTracks(tb_Input.Text, 1, 50, null);
            //gv_Albums.ItemsSource = await lfm.EndPoints.Artist.getTopAlbums(tb_Input.Text, 1, 70, null);
            //var events = await lfm.EndPoints.Artist.getEvents(tb_Input.Text, 1, 50, null);
            //var album = await lfm.EndPoints.Album.getInfo("Jason Mraz", "Mr. A-Z", null);
            //var shouts = await lfm.EndPoints.Album.getShouts("Jason Mraz", "Mr. A-Z", null, null, null);
            //var albumtoptags = await lfm.EndPoints.Album.getTopTags("Jason Mraz", "Mr. A-Z", null);
            //var albumssearch = await lfm.EndPoints.Album.search("Amazing", 1, 50);
            //var buylinks = await lfm.EndPoints.Album.getBuyLinks("Jason Mraz", "Mr. A-Z", "United Kingdom", null);
            //var hypedtracks = await lfm.EndPoints.Chart.getHypedTracks(null, null);
            //var hypedartists = await lfm.EndPoints.Chart.getHypedArtists(null, null);
            //var lovedtracks = await lfm.EndPoints.Chart.getLovedTracks(null, null);
            //var topartists = await lfm.EndPoints.Chart.getTopArtists(null, null);
            /// DOES NOT WORK? //var toptags = await lfm.EndPoints.Chart.getTopTags(null, null);
            //var charttracks = await lfm.EndPoints.Chart.getTopTracks(null, null);

            //var track = await lfm.EndPoints.Track.getInfo("Jason Mraz", "I'm Yours", null);
            //var trackBuyLinks = await lfm.EndPoints.Track.getBuyLinks("Jason Mraz", "I'm Yours", "United Kingdom", null);
            //var trackShouts = await lfm.EndPoints.Track.getShouts("Jason Mraz", "I'm Yours", null, null, null);
            //var trackTopTags = await lfm.EndPoints.Track.getTopTags("Jason Mraz", "I'm Yours", null);
            //var similartracks = await lfm.EndPoints.Track.getSimilar("Jason Mraz", "I'm Yours", 30, null);
            //var tracksearch = await lfm.EndPoints.Track.search("I'm Yours", null, null, null);

            pRing.IsActive = false;
        }

        private async void b_Pos_Click(object sender, RoutedEventArgs e)
        {
            Windows.Devices.Geolocation.Geolocator locator = new Windows.Devices.Geolocation.Geolocator();
            Windows.Devices.Geolocation.Geoposition pos = await locator.GetGeopositionAsync();
            String s = String.Format("Longtitude: {0}, Latitude: {1}", pos.Coordinate.Longitude.ToString(), pos.Coordinate.Latitude.ToString());
            Windows.UI.Popups.MessageDialog msg = new Windows.UI.Popups.MessageDialog(s, "Current Position");
            await msg.ShowAsync();

            pRing.IsActive = true;
            var events = await lfm.EndPoints.Geo.getEvents(pos.Coordinate.Latitude, pos.Coordinate.Longitude, null, null, null);
            pRing.IsActive = false;
        }

        private async void MusicTest()
        {
            var library = Windows.Storage.KnownFolders.MusicLibrary;
            var folders = await library.GetFoldersAsync();

            String em = String.Empty;
        }
    }
}
